package dyyx;

import java.util.ArrayList;
import java.util.List;

import com.github.davidmoten.geo.GeoHash;

public class GeoHashTest {

	public static void main(String[] args) throws Exception {		
		// 经度 longitude 
		// 纬度  Latitude
		
		// 经度  longitude ,  纬度 Latitude
		String[]geopoints = {
				"北京;116.23128;40.22077",
				"上海;121.48941;31.40527",
				"深圳;113.88308;22.55329",
				"杭州;120.21201;30.2084",
				"杭州海创园18号楼;120.0163370211792;30.27988902446744",
				"杭州海创园 5号楼;120.01818238098144;30.28281676146628",
				"西溪湿地东南角;120.09040788378907;30.26328081629187",
				"西溪湿地东北角;120.08620218005372;30.28025593649279",
				"西溪湿地西南角;120.04448846545411;30.247414950550652",
				"西溪湿地西北角;120.04732087817384;30.277735798545145",
				"西溪湿地东门;120.08834794726563;30.27484497238057",
				"西溪湿地北们;120.06972268786622;30.280552419058097",		
		};
		// 南极 45.59848298046874 -78.89005931731181
		// 北美 -102.93667326953125  43.88645878604692
		
		
		List<GpsPoint> list = new ArrayList<>();
		
		for(String item:geopoints) {
			String[]arr = item.split(";");
			// System.out.println(arr[0]+arr[1]+arr[2]);
			double latitude = Double.parseDouble(arr[2]);
			double longitude = Double.parseDouble(arr[1]);
			String str = arr[0] + "    " + GeoHash.encodeHash(latitude, longitude,12);
		    System.out.println(str);    
		    list.add(new GpsPoint(arr[0],longitude,latitude));
		}
		
		// 距离计算
		int num = list.size();
		for(int i=1;i<num;i++) {
			GpsPoint p1 = list.get(i-1);
			GpsPoint p2 = list.get(i);
			double distance = GpsUtil.getDistance(p1.lat, p1.lng, p2.lat, p2.lng);
		    System.out.println(p1.name+"==>"+p2.name +"  "+new Double(distance).longValue()+" 米");    
		}
		
	}
	
	
}
